package com.shuoyue.ycgk.ui.mine.coupon;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.base.BaseMvpActivity;
import com.shuoyue.ycgk.entity.Coupon;
import com.shuoyue.ycgk.ui.course.CourseTypeActivity;
import com.shuoyue.ycgk.ui.mine.vip.MyVipActivity;
import com.shuoyue.ycgk.ui.papergroups.groupcommon.PaperGroupCommonActivity;
import com.shuoyue.ycgk.ui.papergroups.running.RunningInfoActivity;
import com.shuoyue.ycgk.ui.shop.ShopTabActivity;
import com.shuoyue.ycgk.utils.SizeUtil;
import com.shuoyue.ycgk.utils.SpacesItemDecoration;
import com.shuoyue.ycgk.views.dialog.common.HintDialog;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 我的优惠券
 * Forty'7
 */
public class CouponInvilidateActivity extends BaseMvpActivity<CouponContract.Presenter> implements CouponContract.View {

    public static void start(Context context) {
        context.startActivity(new Intent(context, CouponInvilidateActivity.class)
        );
    }

    //    ListWithPage listPageBean;
    @BindView(R.id.page_title)
    TextView pageTitle;
    @BindView(R.id.tv_right)
    TextView tvRight;
    @BindView(R.id.lay_coupon)
    LinearLayout layCoupon;
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;
    @BindView(R.id.refresh_layout)
    SmartRefreshLayout refreshLayout;

    CouponAdapter couponAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_coupon;
    }

    @Override
    protected void initView() {
        pageTitle.setText("失效券");
        layCoupon.setVisibility(View.GONE);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        recyclerView.addItemDecoration(new SpacesItemDecoration(SizeUtil.dip2px(mContext, 4), false));
        couponAdapter = new CouponAdapter(null, 3);
        recyclerView.setAdapter(couponAdapter);
        registEmptyView(couponAdapter);
        couponAdapter.setOnItemChildClickListener((adapter, view, position) -> {
            Coupon coupon = (Coupon) adapter.getItem(position);
            switch (view.getId()) {
                case R.id.tv_explain:
                    HintDialog hintDialog = new HintDialog(mContext,
                            "使用说明", coupon.getUseExplain(), Gravity.LEFT);
                    hintDialog.show();
                    break;

            }
        });
        refreshLayout.setEnableLoadMore(false);
        refreshLayout.setOnRefreshListener(refreshLayout -> {
            mPresenter.getCoupons(0, 1);
            refreshLayout.finishRefresh();
        });
    }

    @Override
    public void initData() {

        super.initData();
        mPresenter = new CouponContract.Presenter();
        mPresenter.attachView(this);
        mPresenter.getCoupons(0, 1);
    }


    @OnClick({R.id.back, R.id.tv_right})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.tv_right:
                break;
        }
    }

    @Override
    public void getCouponList(List<Coupon> list) {
        couponAdapter.resetData(list);
    }
}
